<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>后台-用户列表</title>
    <link href="__PUBLIC__/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="__PUBLIC__/alert/sweetalert.css" rel="stylesheet">
    <script src="__PUBLIC__/jquery/jquery1.8.0.js"></script>
    <script src="__PUBLIC__/alert/sweetalert.min.js"></script>
</head>
<style>
    .add_user{
        float: right;
        padding-right: 10%;
        line-height: 10%;
    }
    body{
    position: relative;
    top: -20px;
}
</style>
<body>

    <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div id="navbar" class="navbar-collapse collapse">
                <a class="navbar-brand" href="{:U('Index/index')}">后台管理系统</a>
                <ul class="nav navbar-nav navbar-right">
                    <!--<li><a href="#">Dashboard</a></li>-->
                    <!--<li><a href="#">Settings</a></li>-->
                    <!--<li><a href="#">Profile</a></li>-->
                    <li><a href="">欢迎您，{$Think.session.user_info.name}</a></li>
                    <li><a href="{:U('Login/out')}">退出</a></li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-2">
                <ul class="nav nav-sidebar">
                    <li><a href="{:U('Index/config')}">配置管理</a></li>
                    <li class="bg-info"><a href="{:U('User/index')}">用户管理</a></li>
                    <li><a href="{:U('Info/index')}">管理记录</a></li>
                    <li><a href="{:U('Info/add')}">添加记录</a></li>
                </ul>
            </div>
            <div class="col-sm-10">
                <h1>用户列表</h1>
                <span><a href="{:U('User/add')}" class="add_user">添加用户</a></span>
                <hr>
                <table class="table table-striped table-hover">
                    <thead>
                    <tr>
                        <th>id</th>
                        <th>用户名</th>
                        <th>创建时间</th>
                        <th>最后登录</th>
                        <th>操作</th>

                    </tr>
                    </thead>
                    <tbody>
                    <volist name="info_list" id="v">
                        <tr>
                            <th scope="row">{$v.id}</th>
                            <td>{$v.name}</td>
                            <td>{$v.create_time|date="Y-m-d H:i:s",###}</td>
                            <td>{$v.last_time|date="Y-m-d H:i:s",###}
                            </td>
                            <td><a href="{:U('User/edit',['id'=>$v['id']])}">编辑</a> | <a class="del_info" href="{:U('User/del',['id'=>$v['id']])}">删除</a></td>
                        </tr>
                    </volist>
                    </tbody>
                </table>
            </div>
        </div>
    </div>


</body>
<script>
    $('.form_info').submit(function(){
        var post_data = $(this).serialize();
        var post_url = $(this).attr('action');
        $.ajax({
            url: post_url,
            type: 'post',
            data: post_data,
            dataType:'json',
            success:function(res){
                switch (res.Code){
                    case 200:
                        swal({
                            title: "Succwss",
                            text: res.Message,
                            type: "success",
                        },function(){
                            window.location.href = res.Data.go_url;
                        });
                        break;
                    case 201:
                    case 203:
                    case 205:
                    case 207:
                        swal('失败', res.Message, "error");
                        break;
                }
            },
            error:function(){

            }
        });
        return false;
    });
    $('.del_info').click(function(){
        delete_url = $(this).attr('href');
        swal({
            title: "真的要删除吗？",
            text: "请确认后点击",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确认删除",
            cancelButtonText: "取消操作",
            closeOnConfirm: false,
            closeOnCancel: false,
        }, function (isConfirm) {
            if (isConfirm) {
                $.ajax({
                    url: delete_url,
                    dataType:'json',
                    success:function(res){
                        switch (res.Code){
                            case 400:
                                swal({
                                    title: "Succwss",
                                    text: res.Message,
                                    type: "success",
                                },function(){
                                    location.reload();
                                });
                                break;
                            case 401:
                                swal("Error", res.Message, "error");
                        }
                    },
                    error:function(){
                    }
                });
            } else {
                swal("已取消", "您取消了本次操作", "info");
            }
        });
        return false;
    });
    $('.get_help').click(function(){
        swal({
        title: "<h3>操作方法</h3>",
        text: '请将<br /><strong style="color: red">微擎->管理公众号->功能选项->借用oAuth权限->oAuth独立域名</strong><br />更改为此值',
        html: true
        });

    });
</script>
</html>
